#ifndef WTHREAD_H
#define WTHREAD_H

#include <QObject>
#include <QThread>
#include <QTableWidget>
#include <QAxObject>
#include <QVariant>
#include <QMap>
//#include "areaconfig.h"

typedef struct CHANNINFO {
    QString AreaID;
    QString ChannelName;
    QString ChannelType;
    QString TXFrequency;
    QString RXFrequency;
    QString ColorCode;
    QString Power;
    QString ChannelMode;
    QString CallType;
    QString OutputTimeslot;
    QString InputTimeslot;
    QString Volume;
    QString MicGain;
    QString Id;
    QString num;
    QString list;
    QString key;
    QString encrypt;
}CHANNINFO;

class wThread : public QThread
{
    Q_OBJECT
public:
    explicit wThread(QObject *parent = nullptr);
    void Table2Excel(QTableWidget *table,QString title);
    void recvPara(QTableWidget *t,QTableWidget *at,QStringList header,QStringList areaheaders,QMap<int,CHANNINFO> *channels);
    void recvQmap(QMap<int,CHANNINFO> *channels);
    void getImportfilepath(QString importfilePath);
    void getExportfilepath(QString importfilePath);
    int openExcel(QString fileName);
    QVariant readAll(QAxObject *sheet);
    int castVariant2ListListVariant(QTableWidget *table,QStringList headers,const QVariant &var);
    int castVariant2ListListVariantchannel(QTableWidget *table,QStringList headers,const QVariant &var);

    void setImport();
    void setExport();
    void table_init();

    void setExportAreaChannel();
    //导出区域表和信道表参数
    void recvParaAreaChannel(QTableWidget *t,QMap<int,CHANNINFO> *map, QString Areafilepath);
    void recvAreaTable(QTableWidget *t,QStringList headers);
    void ExportAreaChannel(QTableWidget *table,QMap<int,CHANNINFO> map,QString fileName);
    QString value_to_index(QString type,QString value);

private:
    QString filename;
    QString importfilePath;
    QString Areafilepath;
    QTableWidget *table;
    QTableWidget *areatable;
    QStringList headers;
    QStringList areaheaders;
    QMap<int,CHANNINFO> channels;
    int flag;
    QString language;

    QTableWidget *Areatable;
    QMap<int,CHANNINFO> *channelmap;

signals:
    void export_ok();
    void export_areachannel_ok();
    void export_failed1();
    void export_failed2();
    void import_ret(int,QMap<int,CHANNINFO> *);

protected:
    void run();
};

#endif // WTHREAD_H
